<?php
try{
	include '../ini.php';
    include '../classes/xl_posts.php';
    $dt_xl_post=new xl_posts;
    if(isset($_GET['id'])){
        $read=$dt_xl_post->read($_GET['id']);
        if($read === false ){
            throw new Exception('Không tồn tại mã này!!!');
        }
        if($_GET['id'] != $read['id']){
            $_GET['id']=$dt_xl_admin->removeSQLI($_GET['id']);
            header("Location: posts_list.php?id=".$_GET['id']);
        }
    }
    $read_list=$dt_xl_post->read_list();
    $list_category=$dt_xl_post->read_category();
    $dt_smarty->assign('list_category',$list_category);
    $dt_smarty->assign('read_list',$read_list);
	$contenForLayout=$dt_smarty->fetch('posts/posts_list.tpl');
	$dt_smarty->assign('contenForLayout',$contenForLayout);
	$dt_smarty->assign('titleForLayout','Danh sách bài viết');
	$dt_smarty->display('layout/defaults.tpl');
    $dbh=NULL;
	
} catch(Exception $e){
    $dbh=NULL;
	$_SESSION['msg']=$e->getMessage();
	$_SESSION['type_msg']='error';
    if(empty($_SERVER['HTTP_REFERER'])){
        header('Location: posts_list.php');
    }else{
        header('Location:'.$_SERVER['HTTP_REFERER']);
    }
    
}
//select (select cat.category_name  from categories cat where cat.id=pos.category_id) parent_id from posts pos
//select pos.post_name  from posts pos left join categories cat on pos.category_id=cat.id
//<img src="../../upload/highlights_{$read.highlights}.png" width="20" height="20" />